﻿using System;
using System.Linq;
using Ones.ServiceUploadManagement;

namespace Ones.Shared
{
    public partial class UploadFiles : System.Web.UI.Page
    {
        private ServiceUploadManagementClient c = null;

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btnUpload_Click(object sender, EventArgs e)
        {
            if (FileUpload1.HasFile)
            {
                string filename = FileUpload1.FileName;
                Label1.Text = filename;

                string location = Server.MapPath("~/Media/") + filename;

                //save to disk
                FileUpload1.PostedFile.SaveAs(location);

                // save to db;
                c = new ServiceUploadManagementClient("uplBasicHttpBiding");
                Media media = new Media();
                
                media.mName = filename;
                media.mLocation = location;
                media.mType = "photo";

                c.saveMedia(media);

                c.Close();
            }
        }
    }
}